package com.me.test.interceptor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 根据开关决定是否启用
 *
 * @author ME
 */
public class Interceptor222 implements HandlerInterceptor {

    private static final Logger log = LoggerFactory.getLogger(Interceptor222.class);

    /**
     * prepare Handle，准备处理，顾名思义，该方法将在 Controller 之前调用，进行一些预处理，
     * 并且可以通过 返回 `false` 中断 Controller 执行。
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        String uri = request.getRequestURI();
        log.info("==> [/**/*.jsp] 匹配指定后缀的路径 preHandle.  url={}", uri);

        return true;
    }

    /**
     * Controller 处理后，将 ModelAndView 返回给前端控制器之前 执行
     *
     * @param request  the request
     * @param response the response
     * @param arg2     the arg 2
     * @param mv       the mv
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object arg2, ModelAndView mv) {
        log.info("<== [/**/*.jsp] 匹配指定后缀的路径 postHandle.  url={}", request.getRequestURI());
    }

    /**
     * 页面渲染完数据后，执行 after进行清理工作）方法
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object arg2, Exception ex) {
        // log.error("<== MyInterceptor afterCompletion - 解析token失败. ex={}", ex.getMessage(), ex);
    }

}
